package com.itheima.ydd.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * @author WuShuai
 * @date 2022/5/22
 */
@Data
@AllArgsConstructor
public class R <T>{
    Map data;

    String errmsg;

    Integer errno;

    public R(){
        data = new HashMap<>();
    }

    public void putData(Object k,Object v){
        data.put(k,v);
    }

    public static R success(String key,Object obj){
        R r = new R();
        Map<Object, Object> map = new HashMap<>();
        map.put(key, obj);
        r.setData(map);
        r.setErrno(0);
        return r;
    }
    public static R success(){
        R r = new R();
        r.setErrno(0);
        return r;
    }
    public static R error(String errmsg){
        R r = new R();
        r.setErrmsg(errmsg);
        r.setErrno(1);
        return r;
    }
}
